using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace OuSuisJeWebRole
{
    public class WebRole : RoleEntryPoint
    {
        public override bool OnStart()
        {

            CloudStorageAccount.SetConfigurationSettingPublisher(
                (configName, configSetter) =>
                {
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                    RoleEnvironment.Changed += (sender, arg) =>
                                                   {
                                                       if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any(change => change.ConfigurationSettingName == configName))
                                                       {
                                                           if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                                                               RoleEnvironment.RequestRecycle();
                                                       }
                                                   };
                });
            return base.OnStart();
        }
    }
}
